/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Model
*        文件名:             BaseSequenceEntity.cs
*        创建系统时间:       2012/11/2 19:07:03
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Model
{
    using System;
    using System.Data;
    using ECP.Utilities;

    [Serializable]
    public class BaseSequenceEntity
    {
        private long degression;
        private string description;
        public bool FillZeroPrefix;
        private string fullName;
        private string id;
        private string oldDegression;
        private string oldSequence;
        private string prefix;
        private string separate;
        private long sequence;
        public int SequenceLength;
        private int step;
        public bool UsePrefix;

        public BaseSequenceEntity()
        {
            this.FillZeroPrefix = true;
            this.SequenceLength = 8;
            this.UsePrefix = true;
            this.oldSequence = string.Empty;
            this.oldDegression = string.Empty;
            this.id = string.Empty;
            this.fullName = string.Empty;
            this.prefix = string.Empty;
            this.separate = string.Empty;
            this.description = string.Empty;
        }

        public BaseSequenceEntity(DataRow dataRow)
        {
            this.FillZeroPrefix = true;
            this.SequenceLength = 8;
            this.UsePrefix = true;
            this.oldSequence = string.Empty;
            this.oldDegression = string.Empty;
            this.id = string.Empty;
            this.fullName = string.Empty;
            this.prefix = string.Empty;
            this.separate = string.Empty;
            this.description = string.Empty;
            this.GetFrom(dataRow);
        }

        public BaseSequenceEntity(DataTable dataTable)
        {
            this.FillZeroPrefix = true;
            this.SequenceLength = 8;
            this.UsePrefix = true;
            this.oldSequence = string.Empty;
            this.oldDegression = string.Empty;
            this.id = string.Empty;
            this.fullName = string.Empty;
            this.prefix = string.Empty;
            this.separate = string.Empty;
            this.description = string.Empty;
            this.GetFrom(dataTable);
        }

        public BaseSequenceEntity GetFrom(DataRow dataRow)
        {
            this.ID = BaseBusinessLogic.ConvertToString(dataRow[BaseSequenceTable.FieldID]);
            this.FullName = BaseBusinessLogic.ConvertToString(dataRow[BaseSequenceTable.FieldFullName]);
            this.Prefix = BaseBusinessLogic.ConvertToString(dataRow[BaseSequenceTable.FieldPrefix]);
            this.Separate = BaseBusinessLogic.ConvertToString(dataRow[BaseSequenceTable.FieldSeparate]);
            this.Sequence = BaseBusinessLogic.ConvertToInt64(dataRow[BaseSequenceTable.FieldSequence]);
            this.Degression = BaseBusinessLogic.ConvertToInt64(dataRow[BaseSequenceTable.FieldDegression]);
            this.Step = BaseBusinessLogic.ConvertToInt(dataRow[BaseSequenceTable.FieldStep]);
            this.Description = BaseBusinessLogic.ConvertToString(dataRow[BaseSequenceTable.FieldDescription]);
            return this;
        }

        public BaseSequenceEntity GetFrom(DataTable dataTable)
        {
            if (dataTable.Rows.Count == 0)
            {
                return null;
            }
            foreach (DataRow row in dataTable.Rows)
            {
                this.GetFrom(row);
                break;
            }
            return this;
        }

        public long Degression
        {
            get
            {
                return this.degression;
            }
            set
            {
                this.degression = value;
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                this.description = value;
            }
        }

        public string FullName
        {
            get
            {
                return this.fullName;
            }
            set
            {
                this.fullName = value;
            }
        }

        public string ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public string OldDegression
        {
            get
            {
                this.oldDegression = this.Degression.ToString();
                if (this.FillZeroPrefix)
                {
                    this.oldDegression = BaseBusinessLogic.RepeatString("0", this.SequenceLength - this.Degression.ToString().Length) + this.Degression.ToString();
                }
                if (this.UsePrefix)
                {
                    this.oldDegression = this.Prefix + this.Separate + this.oldDegression;
                }
                return this.oldDegression;
            }
        }

        public string OldSequence
        {
            get
            {
                this.oldSequence = this.Sequence.ToString();
                if (this.FillZeroPrefix)
                {
                    this.oldSequence = BaseBusinessLogic.RepeatString("0", this.SequenceLength - this.Sequence.ToString().Length) + this.Sequence.ToString();
                }
                if (this.UsePrefix)
                {
                    this.oldSequence = this.Prefix + this.Separate + this.oldSequence;
                }
                return this.oldSequence;
            }
        }

        public string Prefix
        {
            get
            {
                return this.prefix;
            }
            set
            {
                this.prefix = value;
            }
        }

        public string Separate
        {
            get
            {
                return this.separate;
            }
            set
            {
                this.separate = value;
            }
        }

        public long Sequence
        {
            get
            {
                return this.sequence;
            }
            set
            {
                this.sequence = value;
            }
        }

        public int Step
        {
            get
            {
                return this.step;
            }
            set
            {
                this.step = value;
            }
        }
    }
}